<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>echarts</title>
    <style>
      .container1,
      .container2,
      .container3 {
        width: 800px;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <!-- 2. 准备具备宽高的DOM容器 -->
    <div class="container1"></div>
    <div class="container2"></div>
    <div class="container3"></div>
    <!-- 1. 引入echarts js文件 -->
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script>
    <script>
      // 3. 初始化echarts的实例
      const myEcharts1 = echarts.init(document.querySelector(".container1"));
      const myEcharts2 = echarts.init(document.querySelector(".container2"));
      const myEcharts3 = echarts.init(document.querySelector(".container3"));
      // 4. 定义图表配置项option
      const option1 = {
        xAxis: {
          data: [
            "星期一",
            "星期二",
            "星期三",
            "星期四",
            "星期五",
            "星期六",
            "星期日",
          ],
        },
        yAxis: {},
        series: {
          type: "bar",
          data: [155, 100, 125, 105, 99, 155, 166],
        },
      };
      const option2 = {
        xAxis: {
          data: [
            "星期一",
            "星期二",
            "星期三",
            "星期四",
            "星期五",
            "星期六",
            "星期日",
          ],
        },
        yAxis: {},
        series: {
          type: "line",
          data: [155, 100, 125, 105, 99, 155, 166],
        },
      };
      const option3 = {
        series: {
          type: "pie",
          data: [
            { name: "xx", value: 11 },
            { name: "yy", value: 22 },
            { name: "zz", value: 33 },
          ],
          radius: ["20%", "50%"],
        },
      };
      // 5. 渲染图表
      myEcharts1.setOption(option1);
      myEcharts2.setOption(option2);
      myEcharts3.setOption(option3);
    </script>
  </body>
</html>
